<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>随机数的生成</title>
	</head>
	<body>
		<div id="app">
			请输入验证码：<input type="text" id="input"/>
			<button type="button" id="btn" onclick="yz()">提交</button>
			<br>
			<a id="p1" ></a>
			<span onclick="sx()" style="color: blue;">看不清换一张</span>
		</div>
		<script type="text/javascript">
		var codeLength = 6 ;
		var s ="";
			var arr = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','L','I','M','N','U','P','Q','R','S','T','U','V','W','y','z','a','e','f','@','#','$'];
			//生成1-9的随机数
			var p1 = document.getElementById("p1");
			var btn = document.getElementById("btn");
			var input = document.getElementById("input");
			for(let i = 0 ; i < codeLength ; i++){
				var x = Math.floor(Math.random()*39);
				s += arr[x];
				
			}
			p1.innerHTML = s ;
			p1.style.color='red';
			function sx(){
				history.go();//刷新函数
			}
			function  yz(){
				var y = input.value;
				if(y.length <= 0){
					alert("请输入验证码");
				} else if(y.toUpperCase() != s.toUpperCase()){
					alert("验证码输入错误");
					
				} else {
					alert("验证码输入正确");
				}
			}
		</script>
	</body>
</html>
